﻿#include "pch.h"

DYNLIB_HANDLE hAnalysis = NULL;

bool load_analysis_dll()
{
    try
    {
        // init_logging();
#ifdef _WINDOWS        
        hAnalysis = DYNLIB_LOAD("analysis.dll");
#else
         hAnalysis = DYNLIB_LOAD("libanalysis.so");
#endif        
        STD_COUT << "DLL_PROCESS_ATTACH hAnalysis=" << hAnalysis << STD_ENDL;
        if (hAnalysis == NULL)
        {
            STD_CERR << "Load Library analysis.dll failed." << STD_ENDL;
        }
    }
    CATCH_AND_RETURN(false);
    return true;
}

#ifdef _WINDOWS
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        load_analysis_dll();
        // testChemDLL();
    case DLL_THREAD_ATTACH:
        STD_COUT << "DLL_THREAD_ATTACH" << STD_ENDL;
        break;
    case DLL_THREAD_DETACH:
        STD_COUT << "DLL_THREAD_DETACH" << STD_ENDL;
        break;
    case DLL_PROCESS_DETACH:
        std::cout << "DLL_THREAD_DETACH" << std::endl;
        break;
    }
    return TRUE;
}
#else
void __attribute__((constructor)) onProcessAttach()
{
    STD_COUT << "Library is being loaded (similar to DLL_PROCESS_ATTACH)" << STD_ENDL;
    load_analysis_dll();
}
void __attribute__((destructor)) onProcessDetach()
{
    STD_COUT << "Library is being unloaded (similar to DLL_PROCESS_DETACH)" << STD_ENDL;
}
#endif

CHEMDLL_API bool testChemDLL()
{
    STD_COUT << "testChemDLL: " << STD_ENDL;
    STD_COUT << "sizeof(TPRGPARA): " << sizeof(TPRGPARA) << STD_ENDL;
    STD_COUT << "sizeof(AUTOPOOL): " << sizeof(AUTOPOOL) << STD_ENDL;
    STD_COUT << "sizeof(AUTOPARA): " << sizeof(AUTOPARA) << STD_ENDL;
    STD_COUT << "sizeof(TDLLMETRIC): " << sizeof(TDLLMETRIC) << STD_ENDL;
    STD_COUT << "sizeof(TUkPkFactor): " << sizeof(TUkPkFactor) << STD_ENDL;
    STD_COUT << "sizeof(TIPara): " << sizeof(TIPara) << STD_ENDL;
    STD_COUT << "sizeof(AUTOIPARA): " << sizeof(AUTOIPARA) << STD_ENDL;
    STD_COUT << "sizeof(TEPara): " << sizeof(TEPara) << STD_ENDL;
    STD_COUT << "----------------------------------------" << STD_ENDL;
    STD_COUT << "sizeof(TDLLTPRGListItem):" << sizeof(TDLLTPRGListItem) << STD_ENDL;
    STD_COUT << "sizeof(TDLLTPRGINF):" << sizeof(TDLLTPRGINF) << STD_ENDL;
    STD_COUT << "sizeof(TDLLIPINF):" << sizeof(TDLLIPINF) << STD_ENDL;
    STD_COUT << "sizeof(TSegCalibItem):" << sizeof(TSegCalibItem) << STD_ENDL;
    STD_COUT << "sizeof(TDLLIDTListItem):" << sizeof(TDLLIDTListItem) << STD_ENDL;
    STD_COUT << "sizeof(TDLLIDTINF):" << sizeof(TDLLIDTINF) << STD_ENDL;
    STD_COUT << "sizeof(TDLLResultListItem):" << sizeof(TDLLResultListItem) << STD_ENDL;
    STD_COUT << "sizeof(TDLLRESINF):" << sizeof(TDLLRESINF) << STD_ENDL;
    STD_COUT << "sizeof(TRAWBAG):" << sizeof(TRAWBAG) << STD_ENDL;
    STD_COUT << "sizeof(TSMPBAG):" << sizeof(TSMPBAG) << STD_ENDL;
    STD_COUT << "sizeof(TSTDAMTListItem):" << sizeof(TSTDAMTListItem) << STD_ENDL;
    STD_COUT << "sizeof(TAMTINF):" << sizeof(TAMTINF) << STD_ENDL;
    STD_COUT << "sizeof(TSTDCPTListItem):" << sizeof(TSTDCPTListItem) << STD_ENDL;
    STD_COUT << "sizeof(TCPTINF):" << sizeof(TCPTINF) << STD_ENDL;
    STD_COUT << "sizeof(TDLLSTDINF):" << sizeof(TDLLSTDINF) << STD_ENDL;
    STD_COUT << "sizeof(TDLLGROUPListItem):" << sizeof(TDLLGROUPListItem) << STD_ENDL;
    STD_COUT << "sizeof(TDLLGRPINF):" << sizeof(TDLLGRPINF) << STD_ENDL;
    STD_COUT << "sizeof(TDLLEPINF):" << sizeof(TDLLEPINF) << STD_ENDL;
    STD_COUT << "sizeof(TMiscellaneous):" << sizeof(TMiscellaneous) << STD_ENDL;
    STD_COUT << "----------------------------------------" << STD_ENDL;
    STD_COUT << "sizeof(CTORGFileStatus):" << sizeof(CTORGFileStatus) << STD_ENDL;
    STD_COUT << "sizeof(MergedInfo):" << sizeof(MergedInfo) << STD_ENDL;
    STD_COUT << "sizeof(CTORGBag):" << sizeof(CTORGBag) << STD_ENDL;
    STD_COUT << "sizeof(TCalorifParam):" << sizeof(TCalorifParam) << STD_ENDL;
    STD_COUT << "sizeof(TGasoSHTParam):" << sizeof(TGasoSHTParam) << STD_ENDL;
    STD_COUT << "sizeof(THPGParam):" << sizeof(THPGParam) << STD_ENDL;
    STD_COUT << "sizeof(TIntegralMethodHead):" << sizeof(TIntegralMethodHead) << STD_ENDL;
    STD_COUT << "sizeof(TTprgItem):" << sizeof(TTprgItem) << STD_ENDL;
    STD_COUT << "sizeof(TGroupItem):" << sizeof(TGroupItem) << STD_ENDL;
    STD_COUT << "sizeof(CTIntegralMethod):" << sizeof(CTIntegralMethod) << STD_ENDL;
    STD_COUT << "sizeof(TBslSub):" << sizeof(TBslSub) << STD_ENDL;
    STD_COUT << "sizeof(TORGAxisEx):" << sizeof(TORGAxisEx) << STD_ENDL;
    STD_COUT << "sizeof(TSmpCat):" << sizeof(TSmpCat) << STD_ENDL;
    STD_COUT << "sizeof(TMCHead):" << sizeof(TMCHead) << STD_ENDL;
    STD_COUT << "sizeof(TSmpBasic):" << sizeof(TSmpBasic) << STD_ENDL;
    STD_COUT << "sizeof(TClassify):" << sizeof(TClassify) << STD_ENDL;
    STD_COUT << "sizeof(TConcListItem):" << sizeof(TConcListItem) << STD_ENDL;
    STD_COUT << "sizeof(CTSmpInfo):" << sizeof(CTSmpInfo) << STD_ENDL;
    STD_COUT << "sizeof(TSmpInjHead):" << sizeof(TSmpInjHead) << STD_ENDL;
    STD_COUT << "sizeof(TInstHead):" << sizeof(TInstHead) << STD_ENDL;
    STD_COUT << "sizeof(TInstCondHead):" << sizeof(TInstCondHead) << STD_ENDL;
    STD_COUT << "sizeof(TOvenInfo):" << sizeof(TOvenInfo) << STD_ENDL;
    STD_COUT << "sizeof(TPumpInfo):" << sizeof(TPumpInfo) << STD_ENDL;
    STD_COUT << "sizeof(TInletInfo):" << sizeof(TInletInfo) << STD_ENDL;
    STD_COUT << "sizeof(TColumnInfo):" << sizeof(TColumnInfo) << STD_ENDL;
    STD_COUT << "sizeof(TDetectInfo):" << sizeof(TDetectInfo) << STD_ENDL;
    STD_COUT << "sizeof(TAuxiliaryInfo):" << sizeof(TAuxiliaryInfo) << STD_ENDL;
    STD_COUT << "sizeof(TSignalInfo):" << sizeof(TSignalInfo) << STD_ENDL;
    STD_COUT << "sizeof(TPumpCond):" << sizeof(TPumpCond) << STD_ENDL;
    STD_COUT << "sizeof(TAuxCond):" << sizeof(TAuxCond) << STD_ENDL;
    STD_COUT << "sizeof(TDetectCond):" << sizeof(TDetectCond) << STD_ENDL;
    STD_COUT << "sizeof(TColumnCond):" << sizeof(TColumnCond) << STD_ENDL;
    STD_COUT << "sizeof(TInletCond):" << sizeof(TInletCond) << STD_ENDL;
    STD_COUT << "sizeof(TOvenCond):" << sizeof(TOvenCond) << STD_ENDL;
    STD_COUT << "sizeof(TRampItem):" << sizeof(TRampItem) << STD_ENDL;
    STD_COUT << "sizeof(TPumpGradItem):" << sizeof(TPumpGradItem) << STD_ENDL;
    STD_COUT << "sizeof(TWaveLengthItem):" << sizeof(TWaveLengthItem) << STD_ENDL;
    STD_COUT << "sizeof(TFloatRampItem):" << sizeof(TFloatRampItem) << STD_ENDL;
    STD_COUT << "sizeof(TAuxCondEx):" << sizeof(TAuxCondEx) << STD_ENDL;
    STD_COUT << "sizeof(CTInstCond):" << sizeof(CTInstCond) << STD_ENDL;
    STD_COUT << "sizeof(CTORGFile):" << sizeof(CTORGFile) << STD_ENDL;
    STD_COUT << "sizeof(CTMetricConc):" << sizeof(CTMetricConc) << STD_ENDL;
    STD_COUT << "sizeof(TSynResultItem):" << sizeof(TSynResultItem) << STD_ENDL;
    STD_COUT << "sizeof(TOptionHead):" << sizeof(TOptionHead) << STD_ENDL;
    STD_COUT << "sizeof(TChartViewOption):" << sizeof(TChartViewOption) << STD_ENDL;
    STD_COUT << "sizeof(TOnLineOptionHead):" << sizeof(TOnLineOptionHead) << STD_ENDL;
    STD_COUT << "sizeof(TOffLineOptionHead):" << sizeof(TOffLineOptionHead) << STD_ENDL;
    STD_COUT << "sizeof(TCalorifColumnsOption):" << sizeof(TCalorifColumnsOption) << STD_ENDL;
    STD_COUT << "sizeof(CTMROption):" << sizeof(CTMROption) << STD_ENDL;
    STD_COUT << "sizeof(TSmpSettingsHead):" << sizeof(TSmpSettingsHead) << STD_ENDL;
    STD_COUT << "sizeof(CTPFRule):" << sizeof(CTPFRule) << STD_ENDL;
    STD_COUT << "sizeof(CTSmpSettings):" << sizeof(CTSmpSettings) << STD_ENDL;
    STD_COUT << "sizeof(CTCatInfo):" << sizeof(CTCatInfo) << STD_ENDL;
    STD_COUT << "sizeof(TSectionItem):" << sizeof(TSectionItem) << STD_ENDL;
    STD_COUT << "sizeof(TSectionPtItem):" << sizeof(TSectionPtItem) << STD_ENDL;
    STD_COUT << "sizeof(CTDataMerge):" << sizeof(CTDataMerge) << STD_ENDL;
    STD_COUT << "sizeof(CTInstrument):" << sizeof(CTInstrument) << STD_ENDL;

    return true;
}
